home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d13 / nbsamp.arc / NBRCV2.C < prev    next >
Text File  |  1992-01-14  |  3KB  |  103 lines

  1. /* NBRCV2.C -  sample program - receives NetBIOS datagram. -          */
  2. /* Paul McGinnis - AST Research, Data Comm Support - Dept. 430        */
  3. /* Sept. 1988. - comments added 9/26/88                               */
  4. /*                                      */
  5. /* General calling sequence for NetBIOS calls:                        */
  6. /* 1. Set up NCB (Network Control Block)                              */
  7. /* 2. Make ES:BX point to NCB structure                               */
  8. /* 3. Load AX with 100h                                               */
  9. /* 4. Generate an INT 5Ch                                             */
  10. /*                                       */
  11. /* NetBIOS commands and definitions in NETBIOS.H                      */
  12. /*                                      */
  13. /* Compilation information:                                           */
  14. /* Compiler: Borland Turbo C v1.5                                     */
  15. /* Memory model: Small                                                */
  16. /* Floating point support: none                                       */
  17.  
  18.  
  19.  
  20. #include <dos.h>
  21. #include <stdio.h>
  22. #include <netbios.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25.  
  26.  
  27. main()
  28. {
  29.   NCB * rcv_block;
  30.   char * rcv_message;
  31.   char * session;
  32.   char * sender;
  33.   unsigned char ret_code, net_num, iflag;
  34.   rcv_block = (NCB *) malloc(sizeof(NCB));
  35.   rcv_message = (char *) malloc(80);
  36.   session = (char *) malloc(16);
  37.   sender = (char *) malloc(16);
  38.   _AH = 0;
  39.   geninterrupt(0x2a);   /* Check to see if NetBIOS is loaded */
  40.   iflag = _AH;
  41.   if (!iflag)
  42.   {
  43.     puts("    *** ERROR - NetBIOS not installed. ***");
  44.     return;
  45.   }
  46.   printf("Enter network name: ");
  47.   gets(session);
  48.   printf("Enter sender's name: ");
  49.   gets(sender);
  50.   puts("Generating network name...");
  51.   rcv_block -> NCB_COMMAND = ADD_NAME_WAIT;
  52.   rcv_block -> NCB_LANA_NUM = 0;
  53.   rcv_block -> NCB_STO = 0;
  54.   rcv_block -> NCB_RTO = 0;
  55.   strncpy(rcv_block -> NCB_NAME, session, 16);
  56.   strncpy(rcv_block -> NCB_CALLNAME, "*", 16);
  57.   _ES = _DS;
  58.   _BX = rcv_block;
  59.   _AX = 0x100;
  60.   geninterrupt(0x5c);
  61.   ret_code = _AL;
  62.   net_num = rcv_block -> NCB_NUM;
  63.   if (ret_code)
  64.   {
  65.     printf("Bad return code = %02Xh\n", ret_code);
  66.     return;
  67.   }
  68.   printf("Session established. Name number = %02Xh\n", net_num);
  69.   puts("Waiting for datagram...");
  70.   rcv_block -> NCB_RTO = 0;
  71.   strncpy(rcv_block -> NCB_CALLNAME, sender, 16);
  72.   rcv_block -> NCB_BUFFER_OFFSET = rcv_message;
  73.   rcv_block -> NCB_BUFFER_SEGMENT = _DS;
  74.   rcv_block -> NCB_LENGTH = 80;
  75.   rcv_block -> NCB_COMMAND = RECEIVE_DATAGRAM_WAIT;
  76.   _ES = _DS;
  77.   _BX = rcv_block;
  78.   _AX = 0x100;
  79.   geninterrupt(0x5c);
  80.   ret_code = _AL;
  81.   pokeb(_DS, rcv_message + rcv_block -> NCB_LENGTH, 0); /* end buffer with 0 */
  82.   if (ret_code)
  83.     printf("Error number = %02Xh\n", ret_code);
  84.   else
  85.   {
  86.     printf("%c*** %s\n", 7, rcv_message);
  87.     printf("From: %s\n", rcv_block -> NCB_CALLNAME);
  88.   }
  89.   printf("Releasing session >>>%s<<<, number %02Xh\n",
  90.     rcv_block -> NCB_NAME, net_num);
  91.   rcv_block -> NCB_NUM = net_num;
  92.   rcv_block -> NCB_COMMAND = DELETE_NAME_WAIT;
  93.   _ES = _DS;
  94.   _BX = rcv_block;
  95.   _AX = 0x100;
  96.   geninterrupt(0x5c);
  97.   ret_code = _AL;
  98.   if (ret_code)
  99.     printf("Error number = %02Xh.\n", ret_code);
  100.   else
  101.     puts("Completed normally.");
  102. }
  103.